package system

import (
	"5title_gin/global"
	"5title_gin/internal/model"
	"5title_gin/internal/model/system/roles"
	"5title_gin/pkg/db/crud"
)

// RoleService 角色服务
type RoleService struct {
	roleCrud   *crud.CRUD[roles.SysRoles]
	roleVoCrud *crud.CRUD[roles.SysRolesVo]
	roleKvCrud *crud.CRUD[model.KVModel]
}

// NewRoleService 创建角色服务实例
func NewRoleService() *RoleService {
	return &RoleService{
		roleCrud:   crud.NewCRUD[roles.SysRoles](global.DB),
		roleVoCrud: crud.NewCRUD[roles.SysRolesVo](global.DB).Table("sys_roles"),
		roleKvCrud: crud.NewCRUD[model.KVModel](global.DB).Table("sys_roles"),
	}
}

func (s *RoleService) GetRoleList() ([]roles.SysRolesVo, error) {
	rolesList, err := s.roleVoCrud.GetAll().Find()
	if err != nil {
		return nil, err
	}
	return rolesList, nil
}

func (s *RoleService) GetRoleOptions() ([]model.KVModel, error) {
	sysRoles, err := s.roleKvCrud.GetAll().Select("id as value,role_name as label").Find()
	if err != nil {
		return nil, err
	}
	return sysRoles, nil
}
